// pages/houseRenting/houseRenting.js
//获取应用实例
var app = getApp();
//引用
var fileData = require('../../utils/data.js')
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    httpApiImg: app.globalData.httpApiImg,
    banner_url: '',
    advert_url: '',
    navTopItems: fileData.getHouseNavData(),
    bottabData: app.globalData.bottabDataForFwzs,
    houseList: '',
    loadSuccess: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading()
    this.setData({
      ['bottabData[0].current']: true
    })
    fileData.getBannerData.apply(this, ['6', 'top', 0, 'banner_url']); 
    fileData.getBannerData.apply(this, ['6', 'top', 1, 'advert_url']); 
    this.getHouseList()
  },
  // 进入详情页
  enterDetail: function (e) {
    var flag = e.currentTarget.dataset.flag;
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pages/houseDetail/houseDetail?flag=' + flag + '&name=' + item.title + '&id=' + item.id + '&communityName=' + item.communityName
    })
  },
  switchBotab(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  // 搜索
  search: function () {
    wx.navigateTo({
      url: '/pages/houseSearch2/houseSearch2'
    })
  },
  // 猜你喜欢列表
  getHouseList: function(){
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar+ 'tGyHouseSale/getHouseInfosWithParamsByPage', 
      data: {
        houseType: 1,
        sortType : 1
      },
      success: function (res) {
        _this.setData({
          loadSuccess: true
        })
        wx.hideLoading()
        if (res.data.success){
          var houses = res.data.data.houses;
          for(var i = 0; i < houses.length; i++){
            if (houses[i].picture) {
              houses[i].picture = houses[i].picture.split(",");
            }
            if (houses[i].housingCharacteristics){
              houses[i].housingCharacteristics = houses[i].housingCharacteristics.split(",");
            }
          }
          _this.setData({
            houseList: houses
          })
        }
      }
    })
  },
  // 打开小分类
  switchTap: function (e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.getHouseList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})